<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="copyright" content="www.infoearth.com" />
    <title>群测群防数据采集系统</title>
    <link rel="stylesheet" href="../css/api.css">
    <link rel="stylesheet" href="../css/base.css">
    <link rel="stylesheet" href="../lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.css">
    <link rel="stylesheet" href="../lib/leaflet/leaflet.css">
    <script src="../lib/jquery.mobile-1.4.5/jquery.min.js"></script>
    <script src="../lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <script src="../lib/config.js"></script>
    <script src="../lib/common.js"></script>
</head>

<body>
    <div id="wrap">
        <header id='header'>
            <nav id="nav">
                <a id="leftLogo"></a>
                <div id="middle">
                    <strong id="title">群测群防数据采集系统</strong>
                </div>
                <a id="right"> </a>
            </nav>
        </header>
        <div id="main"></div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
apiready = function() {
    $api.fixStatusBar($api.dom('header'));
    api.addEventListener({
        name: 'keyback'
    }, function(ret, err) {
        api.closeWin();
    });
    api.showProgress({
        style: 'default',
        animationType: 'fade',
        title: '正在加载隐患点列表',
        text: '请稍等...',
        modal: false
    });
    var phoneNum = getCookie('PhoneNum');
    //			var filter = "QCQFDSH02070='B' and QCQFD01090='" + phoneNum + "'";
    //			getRecordsByFilter("qcqf", "vwQCQFD", filter, function(response) {
    //				if (response != null && response.record != null && response.record.length > 0) {
    //					showHazardList(response.record);
    //				}
    //			}, showErro, false);
    $.ajax({
        url: ip_req + 'HazardManage/HazardManageService.svc/GetListHazardInfo',
        type: 'GET',
        dataType: 'jsonp',
        data: {
            phone: phoneNum,
        }
    }).done(function(res) {
        api.hideProgress();
        // showMsg(res);
        showHazardList(res.data);
    });
}

function getHazardIcon_old(hazardType) {
    var iconPath = 'widget://image/hazard/01.png';
    switch (hazardType) {
        case '滑坡':
            iconPath = 'widget://image/hazard/01.png';
            break;
        case '崩塌':
            iconPath = 'widget://image/hazard/02.png';
            break;
        case '泥石流':
            iconPath = 'widget://image/hazard/03.png';
            break;
        case '地面塌陷':
            iconPath = 'widget://image/hazard/04.png';
            break;
        case '岩溶塌陷':
            iconPath = 'widget://image/hazard/05.png';
            break;
        case '地面沉降':
            iconPath = 'widget://image/hazard/06.png';
            break;
        case '地裂缝':
            iconPath = 'widget://image/hazard/07.png';
            break;
        case '不稳定斜坡':
            iconPath = 'widget://image/hazard/08.png';
            break;
        default:
            break;
    }
    return iconPath;
}

function getHazardIcon(hazardType) {
    var iconPath = 'widget://image/hazard/01.png';
    switch (hazardType) {
        case '01':
            iconPath = 'widget://image/hazard/01.png';
            break;
        case '02':
            iconPath = 'widget://image/hazard/02.png';
            break;
        case '03':
            iconPath = 'widget://image/hazard/03.png';
            break;
        case '04':
            iconPath = 'widget://image/hazard/04.png';
            break;
        case '05':
            iconPath = 'widget://image/hazard/05.png';
            break;
        case '06':
            iconPath = 'widget://image/hazard/06.png';
            break;
        case '07':
            iconPath = 'widget://image/hazard/07.png';
            break;
        case '00':
            iconPath = 'widget://image/hazard/08.png';
            break;
        default:
            break;
    }
    return iconPath;
}

function showHazardList(record) {
    hazardRecord = record;
    var dataList = [];
    for (var i = 0; i < record.length; i++) {
        var yhd = record[i];
        var yhdId = yhd.JBQK0100;
        var yhdType = yhdId.substr(12, 2);
        var iconPath = getHazardIcon(yhdType);
        var item = {
            uid: yhdId,
            imgPath: iconPath,
            title: yhd.JBQK0110,
            //					subTitle : record[i].QCQFD01050
        };
        dataList.push(item);
    }
    var lstView = api.require('UIListView');
    var header = $api.byId('header');
    var headerPos = $api.offset(header);
    lstView.open({
        rect: {
            x: headerPos.l,
            y: headerPos.t + headerPos.h,
            w: api.frameWidth,
            h: api.frameHeight - headerPos.h
        },
        data: dataList,
        rightBtns: [{
            bgColor: '#388e8e',
            activeBgColor: '',
            width: 70,
            title: '采集数据',
            titleSize: 14,
            titleColor: '#fff',
            icon: '',
            iconWidth: 20
        }, {
            bgColor: '#FF0000',
            activeBgColor: '',
            width: 70,
            title: '上报险情',
            titleSize: 14,
            titleColor: '#fff',
            icon: '',
            iconWidth: 20
        }],
        styles: {
            borderColor: '#EEEEEE',
            item: {
                bgColor: '#F5F5F5',
                activeBgColor: '#AFEEEE',
                height: 55.0,
                imgWidth: 32,
                imgHeight: 32,
                placeholderImg: '',
                titleSize: 16.0,
                titleColor: '#000',
                subTitleSize: 11.0,
                subTitleColor: '#000'
            }
        },
        fixedOn: ''
    }, function(ret) {
        hazardListView_Click(ret);
    });
}

function hazardListView_Click(ret) {

    var hazardInfo = hazardRecord[ret.index];

    var eventType = ret.eventType;
    console.log(eventType);
    switch (eventType) {
        case 'clickImg':
            //定位到灾害点
            setCookie('hazardInfo', JSON.stringify(hazardInfo));
            api.openWin({
                name: 'hazardLocation',
                url: '../html/hazardLocation.html'
            });
            break;
        case 'clickContent':
            //显示灾害点详细信息
            setCookie('hazardInfo', JSON.stringify(hazardInfo));
            api.openWin({
                name: 'hazardInfo',
                url: '../html/hazardInfo.html'
            });
            break;
        case 'clickRightBtn':
            setCookie('hazardInfo', JSON.stringify(hazardInfo));
            if (ret.btnIndex == 0) {
                api.openWin({
                    name: 'hazardInfo',
                    url: '../html/monitorPointList.html'
                });
                //点击了数据采集按钮
            } else {
                api.openWin({
                    name: 'hazardInfo',
                    url: '../html/reportDanger.html'
                });
                //点击了上报险情按钮
            }
            break;
        default:
            break;
    }
}
</script>

</html>
